<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>移动端的事件与穿透</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .mrak {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #333;
      opacity: 0.5;
    }

    a {
      font-size: 30px;
      text-decoration: none;
    }
  </style>
</head>

<body>
  <div class="mrak"></div>
  <a href="https://www.baidu.com/">百度连接</a>
</body>
<script>
  /* 
    点击了div触发事件，后让其隐藏，会出现事件穿透
    解决方法:
      1.阻止默认事件的行为
        e.preventDefault()
      2.使用 fastclick.js 来解决
  */
  "use strict"; {
    document.querySelector(".mrak").addEventListener("touchstart", e => {
      e.target.style.display = "none"
      // 阻止默认行为
      e.preventDefault()
    })
  };
</script>

</html>